#! /bin/mksh

. $(realpath "$0" | xargs dirname)/dmenuconf

shellex()
{
	SCRIPTSH=$(grep -m 1 "#!" "$1" | sed 's/#!//')
	exec $SCRIPTSH "$1" &

	return 0
}

AAA="$(exec dmenu -f -i -b -p EXEC -nb "$DMENUBG" -nf "$DMENUFG" -sb "$DMENUFG" -sf "$DMENUBG" -fn "$DMENUFONT" <<< "$APPLIST")"

for cmdname in $LINKLIST ; do
	if [ "$cmdname" == "$AAA" ] ; then
		exec "$LINKPATH/$cmdname" &
		exit 0
	fi
done

for cmdname in $SHELLDIRLIST ; do
	if [ "$cmdname" == "$AAA" ] ; then
		shellex "$SHELLDIRPATH/$cmdname"
		exit 0
	fi
done

for cmdname in $APPIMAGELIST ; do
	if [ "$cmdname" == "$AAA" ] ; then
		exec "$APPIMAGEPATH/$cmdname" &
		exit 0
	fi
done

case "$AAA" in
	"scrot selection") scrot -s & ;;
	"maim selection") maim -s ~/"$(date +%Y-%m-%d-%k%M%S_maim.png)" & ;;
	*) exec "$AAA" & ;;
esac

exit 0
